<html>

<head>
<title>CS_ProxyJudge ver 1.0</title>
</head>

<body bgcolor="#808080">
<font color="#FFFFFF"><B>
<PRE>
<?php
error_reporting(E_ERROR);
//=======================================================================
// 修改记录：
//     2006-09-26 去掉Referer的判断，避免代理通过统计屏蔽代理验证通过
//
//=======================================================================

  $HTTPHeaderArray[0] ="_PROXY";
  $HTTPHeaderArray[1] ="FORWARDED";
  $HTTPHeaderArray[2] ="HTTP_CACHE_CONTROL";
  $HTTPHeaderArray[3] ="HTTP_CLIENT_IP";
  $HTTPHeaderArray[4] ="HTTP_FORM";
  $HTTPHeaderArray[5] ="HTTP_FORWARDED";
  $HTTPHeaderArray[6] ="HTTP_MAX_FORWARDS";
  $HTTPHeaderArray[7] ="HTTP_PRAGMA";
  $HTTPHeaderArray[8] ="HTTP_PROXY";
  $HTTPHeaderArray[9] ="HTTP_PROXY_CONNECTION";
  $HTTPHeaderArray[10] ="HTTP_VIA";
  $HTTPHeaderArray[11] ="HTTP_X";
  $HTTPHeaderArray[12] ="HTTP_X_BLUECOAT_VIA";
  $HTTPHeaderArray[13] ="HTTP_X_FORWARDED_FOR";
  $HTTPHeaderArray[14] ="HTTP_X_HOST";
  $HTTPHeaderArray[15] ="HTTP_X_REFERER";
  $HTTPHeaderArray[16] ="HTTP_X_SERVER_HOSTNAME";
  $HTTPHeaderArray[17] ="PROXY_";
  $HTTPHeaderArray[18] ="PROXY_HOST";
  $HTTPHeaderArray[19] ="PROXY_PORT";
  $HTTPHeaderArray[20] ="PROXY_REQUEST";
  $HTTPHeaderArray[21] ="REMOTE_IDENT";
  $HTTPHeaderArray[22] ="REMOTE_USER";

  $HTTPHeaderArray[23] ="HTTP_ACCEPT";
  $HTTPHeaderArray[24] ="HTTP_ACCEPT_LANGUAGE";
  $HTTPHeaderArray[25] ="HTTP_ACCEPT_ENCODING";
  $HTTPHeaderArray[26] ="HTTP_USER_AGENT";
  $HTTPHeaderArray[27] ="HTTP_CONNECTION";
  $HTTPHeaderArray[28] ="REMOTE_PORT";
  $HTTPHeaderArray[29] ="HTTP_REFERER";

  $HTTPHeaderArray[30] ="HTTP_X_CLIENT_IP";


  function VerifyerProxyLevel()
  {
    global $GLOBALS;

    if (($_SERVER["REMOTE_IDENT"]=="")
    and ($_SERVER["REMOTE_USER"]=="")
    and ($_SERVER["HTTP_PRAGMA"]=="")
    and ($_SERVER["HTTP_VIA"]=="")
    and ($_SERVER["HTTP_FORM"]=="")
    and ($_SERVER["HTTP_CLIENT_IP"]=="")
    and ($_SERVER["FORWARDED"]=="")
    and ($_SERVER["HTTP_FORWARDED"]=="")
    and ($_SERVER["HTTP_MAX_FORWARDS"]=="")
    and ($_SERVER["HTTP_X"]=="")
    and ($_SERVER["HTTP_X_FORWARDED_FOR"]=="")
    and ($_SERVER["HTTP_X_BLUECOAT_VIA"]=="")
    and ($_SERVER["HTTP_X_HOST"]=="")
    and ($_SERVER["HTTP_X_REFERER"]=="")
    and ($_SERVER["HTTP_X_SERVER_HOSTNAME"]=="")
    and ($_SERVER["HTTP_X_BLUECOAT_VIA"]=="")
    and ($_SERVER["HTTP_PROXY"]=="")
    and ($_SERVER["HTTP_PROXY_CONNECTION"]=="")
    and ($_SERVER["_PROXY"]=="")
    and ($_SERVER["PROXY_"]=="")
    and ($_SERVER["PROXY_HOST"]=="")
    and ($_SERVER["PROXY_PORT"]=="")
    and ($_SERVER["PROXY_REQUEST"]=="")
    and ($_SERVER["HTTP_CACHE_CONTROL"]=="")
    ){
      return HIGH_ANONYMITY;        //超级代理
    }
    if (($_SERVER["HTTP_CLIENT_IP"]=="")
    and ($_SERVER["HTTP_X_CLIENT_IP"]=="")
    and ($_SERVER["FORWARDED"]=="")
    and ($_SERVER["HTTP_FORWARDED"]=="")
    and ($_SERVER["HTTP_MAX_FORWARDS"]=="")
    and ($_SERVER["HTTP_X"]=="")
    and ($_SERVER["HTTP_X_FORWARDED_FOR"]=="")
    and ($_SERVER["HTTP_X_BLUECOAT_VIA"]=="")
    and ($_SERVER["HTTP_X_HOST"]=="")
    and ($_SERVER["HTTP_X_REFERER"]=="")
    and ($_SERVER["HTTP_X_SERVER_HOSTNAME"]=="")
    and ($_SERVER["HTTP_X_BLUECOAT_VIA"]=="")
    ){
      return ANONYMOUS;            //匿名代理
    }else{
      return TRANSPARENT_PROXY;    //透明代理
    }
  }


  //取出所有HTTP提交的变量
  //while ( list( $key, $val ) = each( $_SERVER ) ) {
  //  echo $key."=".$val."\n";
  //}

  echo "----------------------------------------\n";

  for ($i=0;$i<Count($HTTPHeaderArray);$i++){
    if ($_SERVER[$HTTPHeaderArray[$i]]!="")
      echo $HTTPHeaderArray[$i]."=".$_SERVER[$HTTPHeaderArray[$i]]."\n";
  }
  $szRemoteHost = $_SERVER['REMOTE_HOST'];
  $szRemoteAddr = $_SERVER['REMOTE_ADDR'];
  if( $szRemoteHost == $szRemoteAddr || $szRemoteHost == '' ) {
    $szRemoteHost = gethostbyaddr($szRemoteAddr);
    if( $szRemoteHost == '' ) $szRemoteHost = $szRemoteAddr ;
  }

  echo "\n";
  echo "REMOTE_HOST=".$szRemoteHost."\n";
  echo "REMOTE_ADDR=".$szRemoteAddr."\n";

  $ProxyLevel =VerifyerProxyLevel();

  //如果为超级代理，判断HOST是否与ADDR相同（是否全是IP格式地址）
  if ($ProxyLevel=="HIGH_ANONYMITY"){

    if ($szRemoteHost!=$szRemoteAddr){
      $ProxyLevel="ANONYMOUS";
    }
  }

  //有的代理提交的USER_AGENT可能修改为空，直接可判断是通过代理来的，该种代理建议少用
  if ($_SERVER["HTTP_USER_AGENT"]==""){ $ProxyLevel="TRANSPARENT_PROXY";  }

  echo "----------------------------------------\n";
  echo "CS_ProxyJudge Result=$ProxyLevel\n";
  echo "----------------------------------------\n";
  echo "\n\n";
?>
</PRE>
</B>
<font>
</body>

</html>